RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)$
RewriteRule ^(.*) https://www.site.com/domredir.php?name=%1 [R=301,L,NE]